from otree.api import (
    models,
    widgets,
    BaseConstants,
    BaseSubsession,
    BaseGroup,
    BasePlayer,
    Currency as c,
    currency_range,
)


author = 'Your name here'

doc = """
Your app description
"""


class Constants(BaseConstants):
    name_in_url = 'group_rgb'
    players_per_group = 6
    num_rounds = 1


class Subsession(BaseSubsession):
    def creating_session(self):
        # if self.round_number == 1:
        self.group_randomly(fixed_id_in_group=True)  # 随机分队 Id不变
        self.session.vars['group'] = self.get_group_matrix()
        # [[<Player  1>, <Player  2>], [<Player  3>, <Player  4>]]
        # 类似于这样
        # 随机分组函数 将分组结果存到r1 r2 b1 b2里
        # 逐个循环player 1号 2号 3号 4号等玩家

        # 先设置默认值
        # print(self.session.vars['r1'])
        self.session.vars['r1'] = 0
        self.session.vars['r2'] = 0
        self.session.vars['r3'] = 0
        self.session.vars['r4'] = 0
        self.session.vars['r5'] = 0
        self.session.vars['r6'] = 0

        self.session.vars['b1'] = 0
        self.session.vars['b2'] = 0
        self.session.vars['b3'] = 0
        self.session.vars['b4'] = 0
        self.session.vars['b5'] = 0
        self.session.vars['b6'] = 0

        self.session.vars['g1'] = 0
        self.session.vars['g2'] = 0
        self.session.vars['g3'] = 0
        self.session.vars['g4'] = 0
        self.session.vars['g5'] = 0
        self.session.vars['g6'] = 0

        # 双重循环分队 将分队组提出来
        for groups in self.get_group_matrix():
            print("groups")
            print(groups)
            # ggm是大组
            # 标志符 用于分组
            for group in groups:  # 循环红组/蓝组的Id 2个组的其中一个
                if self.session.vars['r1'] == 0:
                    self.session.vars['r1'] = group.id_in_subsession
                    continue
                if self.session.vars['r2'] == 0:
                    self.session.vars['r2'] = group.id_in_subsession
                    continue
                if self.session.vars['r3'] == 0:
                    self.session.vars['r3'] = group.id_in_subsession
                    continue
                if self.session.vars['r4'] == 0:
                    self.session.vars['r4'] = group.id_in_subsession
                    continue
                if self.session.vars['r5'] == 0:
                    self.session.vars['r5'] = group.id_in_subsession
                    continue
                if self.session.vars['r6'] == 0:
                    self.session.vars['r6'] = group.id_in_subsession
                    continue

                if self.session.vars['b1'] == 0:
                    self.session.vars['b1'] = group.id_in_subsession
                    continue
                if self.session.vars['b2'] == 0:
                    self.session.vars['b2'] = group.id_in_subsession
                    continue
                if self.session.vars['b3'] == 0:
                    self.session.vars['b3'] = group.id_in_subsession
                    continue
                if self.session.vars['b4'] == 0:
                    self.session.vars['b4'] = group.id_in_subsession
                    continue
                if self.session.vars['b5'] == 0:
                    self.session.vars['b5'] = group.id_in_subsession
                    continue
                if self.session.vars['b6'] == 0:
                    self.session.vars['b6'] = group.id_in_subsession
                    continue
                if self.session.vars['g1'] == 0:
                    self.session.vars['g1'] = group.id_in_subsession
                    continue
                if self.session.vars['g2'] == 0:
                    self.session.vars['g2'] = group.id_in_subsession
                    continue
                if self.session.vars['g3'] == 0:
                    self.session.vars['g3'] = group.id_in_subsession
                    continue
                if self.session.vars['g4'] == 0:
                    self.session.vars['g4'] = group.id_in_subsession
                    continue
                if self.session.vars['g5'] == 0:
                    self.session.vars['g5'] = group.id_in_subsession
                    continue
                if self.session.vars['g6'] == 0:
                    self.session.vars['g6'] = group.id_in_subsession
                    continue
        self.set_group_matrix(self.session.vars['group'])  # 这个是接受分组 后面的实验要使用这行代码


class Group(BaseGroup):
    pass


class Player(BasePlayer):
    pass
